﻿@using CoreData
@using Helper
@model IList<Product>
@{
    if (Model.Count > 0)
    {
        ViewBag.Title = "Tất cả sản phẩm";
    }
    else
    {
        ViewBag.Title = ViewBag.Title;
    }
    Layout = "~/Views/Shared/_Layout.cshtml";   
}
@section HeadResource{
    <title>Danh mục @ViewBag.Title</title>
    <link rel="stylesheet" type="text/css" href="@Url.Content("~/Content/css/product.css")">
}
@section BottomResource{
    <script type="text/javascript" src="@Url.Content("~/Content/js/product.js")"></script>
}
@helper pagerHelper()
    {
        int totalPage = ViewBag.TotalPage;
        int currentPage = (int)ViewBag.page;
        int i = 0;  
    <ul>
        <li class="bullet-first"><a href="@Url.RouteUrl("product_list")"><<</a></li>
        @if (currentPage > 1)
        {
            <li class="bullet-prev"><a href="@Url.RouteUrl("product_list", new { page = currentPage - 1 })">
                Prev</a></li>
        }
        @if (totalPage > 0)
        {
            var startPage = currentPage - 2;
            var endPage = currentPage + 2;
            if (startPage < 1) { startPage = 1; }
            if (endPage > totalPage) { endPage = totalPage; }

            if (currentPage >= 4)
            {
            <li><a href="#">...</a></li>
            }
            for (i = startPage; i <= endPage; i++)
            {
                if (currentPage == i)
                {
            <li class="current-page"><a href="@Url.RouteUrl("product_list", new { page = i })">@i</a></li>
                }
                else
                {
            <li><a href="@Url.RouteUrl("product_list", new { page = i })">@i</a></li>
                }
            }
            if (currentPage <= totalPage - 2)
            {
            <li><a href="#">...</a></li>
            }
        }
        @if (currentPage < totalPage)
        {
            <li class="bullet-next"><a href="@Url.RouteUrl("product_list", new { page = currentPage + 1 })">
                Next</a></li>
        }
        <li class="bullet-last"><a href="@Url.RouteUrl("product_list", new { page = totalPage })">
            >></a></li>
    </ul>
}
@if (Model != null && Model.Count() > 0)
{
    <div class="grid-view">
        <div class="grid-title">
            <h3>
                Danh sách @ViewBag.Title</h3>
            <div class="link-to-all paging">
                @pagerHelper()
            </div>
        </div>
        <ul class="row-product">
            @foreach (var item in Model)
            {
                <li class="column-product">
                    <div class="column-inner">
                        <div class="product-thumbnail">
                            <a href="@Url.RouteUrl("product_details", new { Id = item.ID, Link = item.Link })" title="@item.Name">
                                <img src="/Media/Product/@item.Image" alt="@item.Image" />
                            </a>
                        </div>
                        <div class="tool-payment">
                            <a href="@Url.Action("BuyNow", "ShoppingCart", new { ProductId = item.ID, Amount = 1 })" class="btn gray btn-pay">
                                Mua ngay</a>
                            <input type="button" ProductId="@item.ID" Amount="1" type="button" class="btn btn-add-cart" title="Thêm vào giỏ hàng">
                        </div>
                        <div class="product-details">
                            @{
                var productname = item.Name;
                if (productname.Length > 25)
                {
                    productname = productname.Substring(0, 25) + "...";
                }

                                <div class="product-price">
                                    <span>@StringHelper.FormatVND(int.Parse(item.Price.ToString()))</span></div>
                                <h1 class="product-title">
                                    <a href="@Url.RouteUrl("product_details", new { Id = item.ID, Link = item.Link })">@productname</a></h1>
                            }
                            <div class="small-detail">
                                <span class="detail-item">
                                    <label>
                                        Hạn dùng:</label><span>@item.Shelf</span></span> <span class="detail-item">
                                            <label>
                                                Xuất sứ:</label><span>Đà Lạt</span></span>
                            </div>
                        </div>
                    </div>
                </li>
            }
        </ul>
        <div class="clearfix">
        </div>
        <div class="grid-title">
            <div class="link-to-all paging">
                @pagerHelper()
            </div>
        </div>
        <div class="clearfix">
        </div>
    </div>
}